import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class TestSwitchAndCheckBoxWidget extends StatefulWidget {
  const TestSwitchAndCheckBoxWidget({super.key});

  @override
  State<StatefulWidget> createState() {
    return SwitchAndCheckBoxState();
  }
}

class SwitchAndCheckBoxState extends State<TestSwitchAndCheckBoxWidget> {
  bool _switch = false;
  bool? _check = true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("基础组件 单选开关和复选框 学习使用"),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Switch(
                value: _switch,
                onChanged: (value) {
                  setState(() {
                    print("Switch setState 1 ${_switch}");
                    _switch = value;
                    print("Switch setState 2 ${_switch}");
                  });
                }),
            Checkbox(
                value: _check,
                tristate: true, // 三态 开关 true = 三态 开关null， false = 二态 开和关
                activeColor: Colors.red,
                onChanged: (value) {
                  setState(() {
                    _check = value;
                  });
                })
          ],
        ),
      ),
    );
  }
}
